package com.fristvue.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fristvue.po.Goods;
import com.fristvue.po.ShopCart;
import com.fristvue.po.Users;
import com.fristvue.po.Util.Page;
import com.fristvue.po.Util.ShopUtil;
import com.fristvue.service.GoodsService;
import com.fristvue.service.ShopCartService;
import com.sun.mail.handlers.image_gif;
/**
 * 购物车的控制层
 * @author 购物车
 */
@RestController
public class ShopCartController {
	@Autowired
	private ShopCartService shopCartService; //购物车
	@Autowired
	private GoodsService goodsService;
	
	/**
	 * 查出该用户的购物车中包含的数据
	 * @return
	 */
	@RequestMapping("/shopCart/{page}/{size}")
	public Page<ShopCart> getUserShopCart(@PathVariable("page") Integer page,
    		@PathVariable("size") Integer size, @RequestBody ShopUtil shopUtil){
		 Integer num = page * size;
		 
	     return this.shopCartService.findShopList(num, size, shopUtil);
	}
	/**
	 * 添加购物车
	 * @param shopCart
	 * @return
	 */
	@PutMapping("addShop")
	public boolean WherefindShopList(@RequestBody ShopCart shopCart){
		double shopPrice = this.goodsService.selectByPrimaryKey
				(shopCart.getGoodsId()).getPrice() * shopCart.getCount();
		shopCart.setShopPrice(shopPrice);
		return this.shopCartService.ShopCartAdd(shopCart);
	}
	/**
	 * 删除购物车
	 * @param shopCartId
	 * @return
	 */
	@DeleteMapping("deleteShopCart")
	public boolean deleteShopCart(Integer id) {
		return this.shopCartService.DeleteShopCart(id);
	}
	
	/**
	 * 显示出购物车的详细信息
	 * @param id
	 * @return
	 */
	@RequestMapping("shopCartById")
	public ShopCart shopCartById(Integer id) {
		return this.shopCartService.shopCartById(id);
		
	}
	
	@PutMapping("updateShopCartId")
	public boolean updateShopCartId(@RequestBody ShopCart shopCart) {
		return this.shopCartService.updatShopCartById(shopCart);
	}
}
